package com.example.lin.day9_29;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    private RecyclerView rv;
    private TabLayout tabLayout;
    private View viewById;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewById = findViewById(R.id.app_bar);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        final FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

//                Toast.makeText(MainActivity.this, "点击了悬浮按钮!", Toast.LENGTH_SHORT).show();

                Snackbar.make(fab, "点击了悬浮按钮!", Snackbar.LENGTH_LONG)

                        .setAction("好吧!", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Toast.makeText(MainActivity.this, "点击了 好吧!", Toast.LENGTH_SHORT).show();
                            }
                        })


                        .show();

            }
        });

        initTabLayout();
        initRecyclerView();

        initTextInputLayout();
    }

    TextInputLayout til = null;

    private void initTextInputLayout() {
        til = findViewById(R.id.til1);
        til.setError("输入有误,请重新输入!");
    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
//        til.setError("");
//        til.setErrorEnabled(false);

        float translationY = viewById.getBottom();
        Log.d("ASDF", "onBackPressed: "+translationY);
    }

    private void initTabLayout() {

//        tabLayout = findViewById(R.id.tabLayout);
//
//        tabLayout.addTab(tabLayout.newTab().setText("关注"));
//        tabLayout.addTab(tabLayout.newTab().setText("推荐"));
//        tabLayout.addTab(tabLayout.newTab().setText("热榜"));
//        tabLayout.addTab(tabLayout.newTab().setText("视频"));


    }

    private void initRecyclerView() {
//        rv = findViewById(R.id.rv);
//
//        rv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
//
//        String[] strs = new String[50];
//        for (int i = 0; i < strs.length; i++) {
//            strs[i] = "item" + i;
//        }
//        rv.setAdapter(new MyAdapter(strs));

    }


    class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {


        class MyViewHolder extends RecyclerView.ViewHolder {

            public MyViewHolder(View itemView) {
                super(itemView);
            }
        }

        private String[] strs;

        public MyAdapter(String... strs) {
            this.strs = strs;
        }

        @NonNull
        @Override
        public MyAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new MyViewHolder(LayoutInflater.from(MainActivity.this).inflate(android.R.layout.simple_list_item_1, parent, false));
        }

        @Override
        public void onBindViewHolder(@NonNull MyAdapter.MyViewHolder holder, int position) {
            TextView itemView = (TextView) holder.itemView;
            itemView.setText(strs[position]);
        }

        @Override
        public int getItemCount() {
            return strs.length;
        }
    }

}
